<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Determine accessibility of a file</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.posix.html">« POSIX 函数</a></li>
      <li style="float: right;"><a href="function.posix-ctermid.html">posix_ctermid »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.posix.html">POSIX 函数</a></li>
    <li>Determine accessibility of a file</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.posix-access" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">posix_access</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">posix_access</span> &mdash; <span class="dc-title">
   Determine accessibility of a file
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.posix-access-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>posix_access</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>posix_access()</strong></span> checks the user&#039;s permission of a file.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.posix-access-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

      <dd>

       <p class="para">
        The name of the file to be tested.
       </p>
      </dd>

     
    
     <dt>
<code class="parameter">flags</code></dt>

      <dd>

       <p class="para">
        A mask consisting of one or more of <strong><code>POSIX_F_OK</code></strong>,
        <strong><code>POSIX_R_OK</code></strong>, <strong><code>POSIX_W_OK</code></strong> and
        <strong><code>POSIX_X_OK</code></strong>.
       </p>
       <p class="para">
        <strong><code>POSIX_R_OK</code></strong>, <strong><code>POSIX_W_OK</code></strong> and
        <strong><code>POSIX_X_OK</code></strong> request checking whether the file
        exists and has read, write and execute permissions, respectively.
        <strong><code>POSIX_F_OK</code></strong> just requests checking for the
        existence of the file.
       </p>
      </dd>

     
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.posix-access-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.posix-access-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3280">
    <p><strong>示例 #1 <span class="function"><strong>posix_access()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     This example will check if the $file is readable and writable, otherwise
     will print an error message.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'some_file'</span><span style="color: #007700">;<br /><br />if&nbsp;(</span><span style="color: #0000BB">posix_access</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">POSIX_R_OK&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">POSIX_W_OK</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'The&nbsp;file&nbsp;is&nbsp;readable&nbsp;and&nbsp;writable!'</span><span style="color: #007700">;<br /><br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$error&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">posix_get_last_error</span><span style="color: #007700">();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Error&nbsp;</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">posix_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.posix-access-notes">
  <h3 class="title">注释</h3>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.posix-access-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.posix-get-last-error.html" class="function" rel="rdfs-seeAlso">posix_get_last_error()</a> - Retrieve the error number set by the last posix function that failed</span></li>
    <li class="member"><span class="function"><a href="function.posix-strerror.html" class="function" rel="rdfs-seeAlso">posix_strerror()</a> - Retrieve the system error message associated with the given errno</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>